<template>
	<view class="container">
		<view class="list">
			<view class="col">
				<view class="left">
					Login password
				</view>
				<view class="right" @click="show=true">
					<text>Change</text>
					<image src="@/static/image/more2.png" mode=""></image>
				</view>
			</view>
			<view class="col">
				<view class="left">
					E-mail
				</view>
				<view class="right">
					<text class="mail">VERIFIED</text> {{userInfo.email}}
				</view>
			</view>
			<view class="col">
				<view class="left">
					Phone
				</view>
				<view class="right" @click="open">
					{{userInfo.mobile}}
					<image src="@/static/image/more2.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="btn" @click="logout">
			Logout
		</view>
		<uni-popup ref="popup">
			<view class="popup">
				<view class="title">
					Update your phone
				</view>
				<phone :phone="userInfo.mobile_format" @getPhone="getPhone" />
				<view class="update" @click="update">
					Update
				</view>
			</view>
		</uni-popup>
		<change :show.sync="show" />
	</view>
</template>

<script>
	import phone from "@/components/addPhone.vue"
	import change from "./changePwd.vue"
	export default {
		components: {
			phone,
			change
		},
		data() {
			return {
				userInfo: {},
				show: false
			}
		},
		onLoad() {
			this.getInfo()
		},
		methods: {
			getInfo() {
				this.$post("/user/userinfo", {
					currency_id: uni.getStorageSync("currency_id")
				}).then(res => {
					this.userInfo = res.data.userinfo
				})
			},
			logout() {
				uni.removeStorageSync("token")
				uni.redirectTo({
					url: "/pages/index"
				})
			},
			open() {
				this.$refs.popup.open()
			},
			getPhone(phone) {
				this.userInfo.mobile = phone
			},
			update() {
				this.$post("/user/changemobile", {
					mobile: this.userInfo.mobile
				}).then(res => {
					this.$toast(res.msg)
					if (res.code == 1) {
						this.$refs.popup.close()
					}
					this.getInfo()
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		border-top: 16rpx solid #F1F2F7;
		padding: 0 32rpx;
	}

	.btn {
		border-radius: 8rpx;
		border: 2rpx solid #E752D6;
		font-size: 32rpx;
		color: #E752D6;
		line-height: 88rpx;
		text-align: center;
		margin-top: 100rpx;
	}

	.list {
		.col {
			border-bottom: 2rpx solid #E6E6E6;
			padding: 40rpx 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 30rpx;

			.right {
				display: flex;
				align-items: center;

				image {
					width: 14rpx;
					height: 26rpx;
					margin-left: 20rpx;
				}

				text {
					color: #E752D6;
				}

				.mail {
					background: linear-gradient(90deg, #3EFDDB, #FF3AD5);
					color: #fff;
					font-size: 24rpx;
					padding: 4rpx 8rpx;
					margin-right: 14rpx;
				}
			}
		}
	}

	.popup {
		background-color: #ffff;
		padding: 40rpx 30rpx;
		border-radius: 10rpx;
		width: 80vw;

		.title {
			margin-bottom: 30rpx;
		}

		.update {
			background: #0C0E27;
			border-radius: 4rpx;
			color: #fff;
			font-size: 30rpx;
			padding: 20rpx;
			width: 300rpx;
			margin: 0 auto;
			margin-top: 50rpx;
			text-align: center;
		}
	}
</style>